<template>
  <div class="wrap">
    <div class="box-left">
      <div class="box-nav">
        <ul>
          <li
            class="nav-box"
            v-for="(item, index) in titltArr"
            :key="index"
            :style="item.color"
          >
            {{ item.name }}
          </li>
        </ul>
      </div>
      <div class="comment" v-for="(item, index) in userList" :key="index">
        <div class="comment-img">
          <img :src="item.touxiang" alt="" />
        </div>
        <div class="comment-user">
          <p class="title">{{ item.name }}</p>
          <p class="time">{{ item.time }}</p>
          <div class="logo">建议</div>
          <div class="desc">{{ item.content }}</div>
          <div class="zan">
            <span @click="zanHandle(index)">
              <img :src="item.zan" alt="" style="width: 14px; height: 14px" />
              {{ item.like }}
            </span>
            <span @click="commentHandle(index)">
              <img :src="item.pinglun" alt="" />
              {{ item.message }}
            </span>
          </div>
          <div class="comment-comment" v-if="item.iscommentFalg">
            <input type="text" />
            <div class="reply" @click="commentHandle1(index)">回复</div>
          </div>
        </div>
      </div>
      <div class="page">
        <Pages :page="980" />
      </div>
    </div>
    <div class="box-right">
      <div class="box-right-top">
        <div class="hander">热门文章</div>
        <ul>
          <li class="hander-desc">周末来，来点好玩的吧！</li>
          <li class="hander-desc">周末来，来点好玩的吧！</li>
          <li class="hander-desc">周末来，来点好玩的吧！</li>
          <li class="hander-desc">周末来，来点好玩的吧！</li>
        </ul>
      </div>
      <div class="box-right-bottom">
        <div class="hander">活跃用户</div>
        <div class="active-user">
          <img
            :src="item"
            alt=""
            v-for="(item, index) in imgArr"
            :key="index"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { Dialog } from "vant";
import Pages from "../../components/Pages";
export default {
  components: {
    Pages,
  },
  data() {
    return {
      titltArr: [
        {
          color: "background: red;",
          name: "全部",
        },
        {
          color: "background: orange;",
          name: "建议",
        },
        {
          color: "background: orangered;",
          name: "账号",
        },
        {
          color: "background: blueviolet;",
          name: "问题",
        },
        {
          color: "background: blue;",
          name: "举报",
        },
        {
          color: "background: lightskyblue;",
          name: "公告",
        },
      ],
      userList: [],
      imgArr: [
        "http://iwenwiki.com/api/blueberrypai/image/lanmeijiang/1.jpg",
        "http://iwenwiki.com/api/blueberrypai/image/lanmeijiang/2.jpg",
        "http://iwenwiki.com/api/blueberrypai/image/lanmeijiang/3.jpg",
        "http://iwenwiki.com/api/blueberrypai/image/lanmeijiang/4.jpg",
      ],
    };
  },
  methods: {
    zanHandle(index) {
      this.userList[index].isZanFalg = !this.userList[index].isZanFalg;
      if (this.userList[index].isZanFalg) {
        this.userList[index].like += 1;
        this.userList[index].zan =
          "http://iwenwiki.com/api/blueberrypai/indexImg/zan-big_03.png";
      } else {
        this.userList[index].like -= 1;
        this.userList[index].zan =
          "http://iwenwiki.com/api/blueberrypai/image/listenSpeak/gray-appl.png";
      }
    },
    commentHandle(index) {
      this.userList[index].iscommentFalg = !this.userList[index].iscommentFalg;
      this.userList[index].message += 1;
      this.userList[index].message -= 1;
    },
    commentHandle1(index) {
      Dialog.confirm({
        message: "确认回复",
      })
        .then(() => {
          this.userList[index].iscommentFalg = false;
          // on confirm
          this.userList[index].message += 1;
        })
        .catch(() => {
          this.userList[index].iscommentFalg = false;
          this.userList[index].message += 1;
          this.userList[index].message -= 1;
          // on cancel
        });
    },
    http(id) {
      this.$api
        .comment({
          conmment_id: id,
        })
        .then((res) => {
          if (res.data.success) {
            this.userList = res.data.commentInfo.comment;
            for (var i = 0; i < this.userList.length; i++) {
              this.userList[i].zan =
                "http://iwenwiki.com/api/blueberrypai/image/listenSpeak/gray-appl.png";
              this.userList[i].pinglun =
                "http://iwenwiki.com/api/blueberrypai/image/listenSpeak/gray-wechat.png";
              this.userList[i].iscommentFalg = false;
              this.userList[i].isZanFalg = false;
              this.userList[i].touxiang =
                "http://iwenwiki.com/api/" +
                String(res.data.commentInfo.writer.head_pic).slice(24);
            }
          }
        });
    },
  },
  mounted() {
    this.http(1);
    this.$bus.$on("pageVal", (data) => {
      this.http(data);
    });
  },
};
</script>

<style lang="less" scoped>
.wrap {
  width: 1200px;
  margin: 0 auto;
  overflow: hidden;
}
.box-left {
  border-radius: 5px;
  margin: 20px 20px 0 0;
  float: left;
  background: #fff;
  width: 880px;
  .box-nav {
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    overflow: hidden;
    .nav-box {
      width: 70px;
      float: left;
      margin: 50px 40px 50px 0;
      padding: 5px;
      color: #fff;
      border-radius: 3px;
      cursor: pointer;
    }
  }
}
.box-nav ul:nth-child(1) {
  margin-left: 80px;
}
.comment {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  padding-bottom: 20px;
  .comment-img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    float: left;
    margin: 40px 10px 0 50px;
    overflow: hidden;
    img {
      width: 40px;
      height: 40px;
    }
  }
  .comment-user {
    width: 760px;
    float: left;
    margin-top: 40px;
    text-align: left;
    overflow: hidden;
    .title {
      color: rgba(54, 123, 252, 0.801);
      margin: 0 0 5px;
    }
    .time {
      color: #999;
      font-size: 12px;
    }
    .logo {
      padding: 2px 10px;
      border: 1px solid orange;
      color: orange;
      border-radius: 30px;
      position: absolute;
      top: 40px;
      right: 20px;
      font-size: 12px;
    }
    .desc {
      margin-top: 10px;
      line-height: 20px;
      letter-spacing: 1px;
    }
  }
}
.zan {
  margin: 10px 0;
  float: right;
  span {
    margin-left: 10px;
    font-size: 14px;
    color: #999;
    cursor: pointer;
  }
}
.comment-comment {
  border: 1px solid #999;
  margin: 50px 0 20px;
  background: #f2f2f2;
  overflow: hidden;
  height: 110px;
  input {
    box-sizing: border-box;
    width: 660px;
    height: 35px;
    border: 1px solid #999;
    margin-top: 20px;
    float: left;
  }
  .reply {
    width: 80px;
    height: 35px;
    background: orange;
    color: #fff;
    border-radius: 5px;
    letter-spacing: 15px;
    line-height: 35px;
    text-align: right;
    margin-top: 20px;
    margin-left: 18px;
    float: left;
    cursor: pointer;
  }
}
.page {
  margin: 30px 0;
}
.box-right {
  float: left;

  .box-right-top,
  .box-right-bottom {
    text-align: left;
    box-sizing: border-box;
    border-radius: 5px;
    margin-top: 20px;
    background: #fff;
    width: 300px;
    padding: 10px;
    .hander {
      padding-bottom: 10px;
      border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    }
    ul {
      .hander-desc {
        font-size: 14px;
        margin: 10px 0;
        cursor: pointer;
      }
    }
  }
}
.hander-desc:hover {
  color: #109d59;
}
.active-user {
  margin: 10px auto;
  overflow: hidden;
  img {
    width: 139px;
    height: 139px;
    margin: 0 1px 1px 0;
    float: left;
  }
}
</style>